package com.hainatong.jcmvvmbase.mainhome.fragment;

import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.blankj.utilcode.util.ToastUtils;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentRecyclerviewBinding;
import com.hainatong.jcmvvmbase.mainhome.adapter.MessageAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.PlatfromMessage;
import com.hainatong.mvvmbase.base.NoViewModel;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;

import java.util.ArrayList;
import java.util.List;

public class MessageListFragment extends MvvmLazyFragment<FragmentRecyclerviewBinding , NoViewModel>
{

    private MessageAdapter messageAdapter;
    private List<PlatfromMessage> messageList;
    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_recyclerview;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {

    }

    @Override
    protected void initView(View view)
    {
        messageList = new ArrayList<>();
        messageAdapter = new MessageAdapter();
        viewDataBinding.recyclerview.setAdapter( messageAdapter );
        viewDataBinding.recyclerview.setHasFixedSize(true);
        viewDataBinding.recyclerview.setLayoutManager( new LinearLayoutManager( getActivity() ));

        viewDataBinding.refreshlayout.setRefreshHeader( new ClassicsHeader(getActivity()));
        viewDataBinding.refreshlayout.setRefreshFooter( new ClassicsFooter( getActivity() ));
        viewDataBinding.refreshlayout.setOnRefreshListener( refreshLayout -> {

            messageList.add(  new PlatfromMessage("14:33","休假申请","您收到来自轮机长-王磊的休假申请，请尽快审批")  );
            messageList.add(  new PlatfromMessage("14:33","休假申请","您收到来自轮机长-王磊的休假申请，请尽快审批")  );
            messageList.add(  new PlatfromMessage("14:33","休假申请","您收到来自轮机长-王磊的休假申请，请尽快审批")  );
            messageList.add(  new PlatfromMessage("14:33","休假申请","您收到来自轮机长-王磊的休假申请，请尽快审批")  );
            messageAdapter.addData(messageList );

            refreshLayout.finishRefresh(true);

        } );
        viewDataBinding.refreshlayout.setOnLoadMoreListener( refreshLayout -> {

            refreshLayout.finishLoadMore( true );

        } );


        messageAdapter.setOnItemClickListener( (adapter, view1, position) -> {

            ToastUtils.showShort( messageAdapter.getItem(position).getMsg() );

        } );
    }





}
